//package com.xjscrm.console.chat.mq.impl;
//
//import com.alibaba.fastjson.JSON;
//import com.uzai.mobile.collect.api.dto.MicaTransDto;
//import com.uzai.mobile.collect.api.dto.msg.MicaConversationDeleteMsg;
//import com.uzai.mobile.collect.api.enums.MicaMsgType;
//import com.xjscrm.common.entity.WwDevice;
//import com.xjscrm.console.chat.dispatch.MsgDispatcher;
//import com.xjscrm.console.chat.frame.dto.ChatSessionDTO;
//import com.xjscrm.console.chat.frame.send.SConversationDelMsg;
//import com.xjscrm.console.chat.mq.MsgHandler;
//import com.xjscrm.console.dto.chat.ChatTalkSessionQueryDTO;
//import com.xjscrm.console.service.customer.chat.ChatTalkSessionService;
//import com.xjscrm.console.service.customer.wwDevice.WwDeviceService;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang3.ObjectUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//import org.springframework.transaction.annotation.Transactional;
//
//import java.util.Objects;
//
///**
// * @author mingyang.chen create in 2024/3/11 18:14
// */
//@Component
//@Slf4j
//public class ConversationDelMsgHandler implements MsgHandler<MicaConversationDeleteMsg> {
//
//    @Autowired
//    private ChatTalkSessionService chatTalkSessionService;
//
//    @Autowired
//    private MsgDispatcher msgDispatcher;
//
//    @Autowired
//    private WwDeviceService wwDeviceService;
//
//    @Override
//    public MicaMsgType msgType() {
//        return MicaMsgType.CONVERSATION_DELETE;
//    }
//
//    @Override
//    public Class<MicaConversationDeleteMsg> msgClass() {
//        return MicaConversationDeleteMsg.class;
//    }
//
//    @Override
//    @Transactional
//    public void doHandle(MicaConversationDeleteMsg micaFriendTalkMsg) {
//
//        MicaTransDto micaTransDto = baseCache.get();
//
//        Long merId = micaTransDto.getMerId();
//        String deviceId = micaTransDto.getDeviceId();
//        Integer deviceType = micaTransDto.getDeviceType();
//
//        String conversationId = micaFriendTalkMsg.getGroupId();
//
//        if (!ObjectUtils.allNotNull(conversationId, merId, deviceType) || StringUtils.isBlank(deviceId)) {
//            log.error("MicaConversationDeleteMsg is illegal: {}", JSON.toJSONString(micaFriendTalkMsg));
//            return;
//        }
//        //
//        WwDevice wwDevice = wwDeviceService.getByDeviceId(merId, deviceId);
//        if (Objects.isNull(wwDevice)) {
//            log.error("MicaConversationDeleteMsg device is not found: {}", deviceId);
//            return;
//        }
//
//        ChatTalkSessionQueryDTO query = new ChatTalkSessionQueryDTO();
//        query.setMerId(merId);
//        query.setDeviceId(deviceId);
//        query.setDeviceType(deviceType);
//        query.setConversationId(conversationId);
//
//        // 删除回话, 如何不存在
//        ChatSessionDTO talkSession = chatTalkSessionService.get(query);
//        if (Objects.nonNull(talkSession)) {
//            chatTalkSessionService.delete(merId, talkSession.getId());
//
//            SConversationDelMsg conversationDelMsg = new SConversationDelMsg();
//            conversationDelMsg.setDeviceUniqueId(wwDevice.getId());
//            conversationDelMsg.setConversationId(conversationId);
//            conversationDelMsg.setId(talkSession.getId());
//
//            // msgDispatcher.dispatch(conversationDelMsg);
//        }
//    }
//}
